// suo_demo/pages/detail/detail.js
// var htmlToWxml = require("../../../we7/resource/js/htmlToWxml.js");
var WxParse = require('../../../we7/wxParse/wxParse.js');
var app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    listitem: [],
    currentTab: 0,
    show: 'none'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that =this
    console.log(options)
    this.setData({
      id: options.id
    })
    get_details(this, options.id)
    wx.getStorage({
      key: 'jl_user',
      success: function (res) {
        console.log(res)
        that.setData({
          user: res.data
        })
        if (res.data.token){
          record_browse(res.data.token, options.id)
        }
      },
    })
   
  },
  swichNav: function (e) {
    var that = this
    console.log(this.data.currentTab)
    if (this.data.currentTab === e.target.dataset.current){
      return false
    }
    else{
      that.setData({
        currentTab: e.target.dataset.current,
      }) 
    }
  },
  bannertap: function (e) {
    // var tid = e.currentTarget.dataset.id
    var name = e.currentTarget.dataset.name;
    var yid = e.currentTarget.dataset.yid;
    var price = e.currentTarget.dataset.price;
    console.log(e)
    wx.navigateTo({
      url: '../order/order?yid='+yid+'&name='+name+'&price='+price,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})

function get_details(that,id){
  app.util.request({
    'url': 'entry/wxapp/information_details',
    'cachetime': '30',
    data: {
      tid: id,
    },
    success: function (res) {
      
      if (res.data.status){
        // console.log(res.data)
        var ret = res.data;
        var retlist = res.data.data[0]
        var lists = [];
        var items =ret.data[0].list;
        // for (var i = 0; i < retlist.list.length; i++) {
        //   // console.log(i)
        //   items.push({
        //     id: retlist.list[i].id,
        //     ticketName: retlist.list[i].ticketName,
        //     priceDistribute: retlist.list[i].priceDistribute,
        //     priceOriginal: retlist.list[i].priceOriginal,
        //     special_price: retlist.list[i].special_price,
        //     // orderNotice: retlist.list[i].orderNotice
        //   })
        //   console.log(items)
        // }
          lists.push({
            cityname: ret.data[0].cityName,
            coverPic: ret.data[0].coverPic,
            starting_price: ret.data[0].starting_price,
            sceneryAddress: ret.data[0].sceneryAddress,
            sceneryName: ret.data[0].sceneryName,
            // details: htmlToWxml.html2json(ret.data[0].details) 
          })

          
          WxParse.wxParse('article', 'html', ret.data[0].details, that, 5);

          that.setData({
            list: lists,
            listitem: items
          }) 
      }
      
    }
  });
}

// 记录浏览记录
function record_browse(token, tid) {
  app.util.request({
    url: 'entry/wxapp/recording',
    data: {
      token: token,
      tid: tid,
    },
    success: function (res) {
      var ret = res.data;
      console.log(ret)
    }
  })
}